package cn.gmph.blog.service.term.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import cn.gmph.blog.service.term.entity.TermsDO;
import cn.gmph.blog.service.term.dao.helper.TermsProvider;

import java.util.List;;

public interface TermsDAO {

    @Results({ @Result(column = "term_id", property = "termId"), @Result(column = "term_group", property = "termGroup") })
    @Select("SELECT * FROM wp_terms ")
    public List<TermsDO> findAll();

    @Results({ @Result(column = "term_id", property = "termId"), @Result(column = "term_group", property = "termGroup") })
    @Select("SELECT * FROM wp_terms WHERE term_id = #{id}")
    public TermsDO getById(@Param("id") Long id);

    @Insert("INSERT into wp_terms(term_id,name,slug,term_group) VALUES (#{termId},#{name},#{slug},#{termGroup})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(TermsDO terms);

    @Delete("DELETE FROM wp_terms WHERE term_id = #{id}")
    public int deleteById(@Param("id") Long id);

    @UpdateProvider(type = TermsProvider.class, method = "update")
    public int update(@Param("terms") TermsDO terms);

    @Results({ @Result(column = "term_id", property = "termId"), @Result(column = "term_group", property = "termGroup") })
    @SelectProvider(type = TermsProvider.class, method = "pageList")
    public List<TermsDO> pageList(@Param("terms") TermsDO terms, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = TermsProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("terms") TermsDO terms);

}